package logic

import (
	"context"
	"product-user-module/model/mysql"

	"product-user-module/productrpc/internal/svc"
	"product-user-module/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *ProductAddLogic) ProductAdd(in *productrpc.ProductAddRequest) (*productrpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line

	goods := &mysql.Goods{
		Title:     in.Title,
		GoodPrice: float64(in.GoodPrice),
		GoodStock: in.GoodStock,
		UserId:    in.UserId,
	}

	err := goods.GoodAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &productrpc.ProductAddResponse{
		ProductId: int64(goods.ID),
	}, nil
}
